<?php
/**
 * The functions file is used to initialize everything in the theme.  It controls how the theme is loaded and
 * sets up the supported features, default actions, and default filters.  If making customizations, users
 * should create a child theme and make changes to its functions.php file (not this one).  Friends don't let
 * friends modify parent theme files. ;)
 *
 * Child themes should do their setup on the 'after_setup_theme' hook with a priority of 11 if they want to
 * override parent theme features.  Use a priority of 9 if wanting to run before the parent theme.
 *
 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
 * General Public License version 2, as published by the Free Software Foundation.  You may NOT assume
 * that you can use any other version of the GPL.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU General Public License along with this program; if not, write
 * to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 *
 * @package Trending
 * @subpackage Functions
 * @version 0.1.0
 * @author Justin Tadlock <justin@justintadlock.com>
 * @copyright Copyright (c) 2011, Justin Tadlock
 * @link http://themehybrid.com/themes/trending
 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 */

/* Load the core theme framework. */
require_once( trailingslashit( TEMPLATEPATH ) . 'library/hybrid.php' );
$theme = new Hybrid();

/* Do theme setup on the 'after_setup_theme' hook. */
add_action( 'after_setup_theme', 'trending_theme_setup' );

/**
 * Theme setup function.  This function adds support for theme features and defines the default theme
 * actions and filters.
 *
 * @since 0.1.0
 */
function trending_theme_setup() {

	/* Get action/filter hook prefix. */
	$prefix = hybrid_get_prefix();

	/* Add theme support for core framework features. */
	add_theme_support( 'hybrid-core-menus', array( 'primary', 'subsidiary' ) );
	add_theme_support( 'hybrid-core-sidebars', array( 'primary', 'secondary', 'header', 'before-content', 'after-content', 'after-singular' ) );
	add_theme_support( 'hybrid-core-widgets' );
	add_theme_support( 'hybrid-core-shortcodes' );
	//add_theme_support( 'hybrid-core-post-meta-box' );no longer needed
	add_theme_support( 'hybrid-core-theme-settings' );
	add_theme_support( 'hybrid-core-meta-box-footer' );
	add_theme_support( 'hybrid-core-drop-downs' );
	add_theme_support( 'hybrid-core-seo' );
	add_theme_support( 'hybrid-core-template-hierarchy' );

	/* Add theme support for framework extensions. */
	add_theme_support( 'theme-layouts', array( '1c', '2c-l', '2c-r', '3c-l', '3c-r', '3c-c' ) );
	add_theme_support( 'post-stylesheets' );
	add_theme_support( 'dev-stylesheet' );
	add_theme_support( 'loop-pagination' );
	add_theme_support( 'get-the-image' );
	add_theme_support( 'breadcrumb-trail' );
	add_theme_support( 'cleaner-gallery' );

	/* Add theme support for WordPress features. */
	add_theme_support( 'automatic-feed-links' );
	//add_custom_background( 'trending_custom_background_callback' );

	/* Embed width/height defaults. */
	//add_filter( 'embed_defaults', 'trending_embed_defaults' );

	/* Filter the sidebar widgets. */
	//add_filter( 'sidebars_widgets', 'trending_disable_sidebars' );
	//add_action( 'template_redirect', 'trending_one_column' );

	/* Add classes to the comments pagination. */
	//add_filter( 'previous_comments_link_attributes', 'trending_previous_comments_link_attributes' );
	//add_filter( 'next_comments_link_attributes', 'trending_next_comments_link_attributes' );

	/* Add an avatar class to the comments class. */
	//add_filter( 'comment_class', 'trending_comment_class' );

	/* Add custom image sizes. */
	//add_action( 'init', 'trending_add_image_sizes' );
}

?>

<?php
if (function_exists('register_sidebar')) {
	register_sidebar(array(
		'name' => 'Bottom Sidebar',
		'description' => '底部边栏',
		'before_widget' => '<li id="%1$s" class="widget %2$s">',
		'after_widget' => '</li>',
		'before_title' => '<h2 class="widgettitle">',
		'after_title' => '</h2>',
	));
}
/**
 * pagenav
 **/
function yuguo_navi() {
  global $wp_query, $wp_rewrite;
  $pages = '';
  $max = $wp_query->max_num_pages;
  if (!$current = get_query_var('paged')) $current = 1;
  $a['base'] = ($wp_rewrite->using_permalinks()) ? user_trailingslashit( trailingslashit( remove_query_arg( 's', get_pagenum_link( 1 ) ) ) . 'page/%#%/', 'paged' ) : @add_query_arg('paged','%#%');
  if( !empty($wp_query->query_vars['s']) ) $a['add_args'] = array( 's' => get_query_var( 's' ) );
  $a['total'] = $max;
  $a['current'] = $current;
  //custom pagenav
  $total = 0; //1 - display the text "Page N of N", 0 - not display
  $a['mid_size'] = 2; //how many links to show on the left and right of the current
  $a['end_size'] = 1; //how many links to show in the beginning and end
  $a['prev_text'] = '«'; //text of the "Previous page" link
  $a['next_text'] = '»'; //text of the "Next page" link
  $a['type'] = 'plain';
  if ($max > 1) echo '<div class="yuguo-pagenavi">';
  if ($total == 1 && $max > 1) $pages = '<span class="pages">Page ' . $current . ' of ' . $max . '</span>'."\r\n";
  echo $pages . paginate_links($a);
  if ($max > 1) echo '</div>';
}

function custom_comment_fun($comment, $args, $depth) {
  $GLOBALS['comment'] = $comment; ?>
  <li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
    <div id="comment-<?php comment_ID(); ?>" class="comment-body">
      <?php echo get_avatar($comment,$size=$args['avatar_size']); ?>
      <div class="comment-head">
        <cite><?php comment_author_link(); ?></cite><span class="says">Says：</span>
      <?php if ($comment->comment_approved == '0') : ?>
      <em><?php _e('您的评论正在等待审核') ?></em>
      <?php endif; ?>
      <div class="comment-meta commentmetadata">
        <a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><?php echo get_comment_date('Y M d');?> <?php echo get_comment_time();?></a>
        <?php edit_comment_link(__('(Edit)'),'&nbsp;&nbsp;','') ?>
      </div>
      </div>
      <?php comment_text(); ?>
      <div class="reply">
        <?php comment_reply_link(array_merge( $args, array('depth' => $depth,'reply_text' => '回复', 'max_depth' => $args['max_depth']))) ?>
      </div>
    </div>
   <?php
  // Do not include the </li> tag.
}

add_action( 'init', 'register_my_menus' );
/**
 * @return void
 * register the menu of the top
 */
function register_my_menus() {
register_nav_menus();
}

/**
 * set the feature category id
 */
function activate_featureposts() {
  add_option('feature_post_category_id', '1');
}

function deactive_featureposts() {
  delete_option('feature_post_category_id');
}

register_activation_hook(__FILE__, 'activate_featureposts');
register_deactivation_hook(__FILE__, 'deactive_featureposts');

function admin_init_featureposts() {
  register_setting('featureposts', 'feature_post_category_id');
}

function admin_menu_featureposts() {
  add_submenu_page('themes.php','Feature Posts', 'Feature Posts', 8, 'featureposts', 'options_page_featureposts');
}

function options_page_featureposts() {
  include('options-feature-posts.php');
}

if (is_admin()) {
  add_action('admin_init', 'admin_init_featureposts');
  add_action('admin_menu', 'admin_menu_featureposts');
}

/**
 * set the doc's width
 */
function activate_docwidth() {
  add_option('doc_width_id', 'doc');
}

function deactive_docwidth() {
  delete_option('doc_width_id');
}

register_activation_hook(__FILE__, 'activate_docwidth');
register_deactivation_hook(__FILE__, 'deactive_docwidth');

function admin_init_docwidth() {
  register_setting('docwidth', 'doc_width_id');
}

function admin_menu_docwidth() {
  add_submenu_page('themes.php','Theme Width', 'Theme Width', 8, 'docwidth', 'options_page_docwidth');
}

function options_page_docwidth() {
  include('options-docwidth.php');
}

if (is_admin()) {
  add_action('admin_init', 'admin_init_docwidth');
  add_action('admin_menu', 'admin_menu_docwidth');
}
?>